<template>
  <Modal v-model="modalView" width="360"  @on-cancel="onAgreeCancel">
    <p slot="header">
      <Icon type="ios-information-circle"></Icon>
      <span>补货设置</span>
    </p>
    <div style="text-align:center">
      <Form
        label-position="right"
        :label-width="0"
        ref="form"
        :rules="rules"
        :model="form">
        <FormItem label prop="replenish">
          <Input v-model="form.replenish" placeholder="请输入补货"/>
        </FormItem>
      </Form>
    </div>
    <div slot="footer">
      <Button size="large" type="text" @click="onAgreeCancel">取消</Button>
      <Button type="primary" size="large" @click="onAgree">确认</Button>
    </div>
  </Modal>
</template>
<script>
export default {
  data() {
    return {
      modalView: false,
      id: this.$route.query.id || '',
      isLimitBrand: '',
      form: {
        replenish: ''
      },
      rules: {
        replenish: [{required: true, message: '请输入补货数量', trigger: 'blur'}]
      }
    }
  },
  methods: {
    reset(item) {
      this.id = item.acId
      this.isLimitBrand = item.isLimitBrand
      this.modalView = true
    },
    onAgree() {
      this.$refs['form'].validate(valid => {
        if(valid) {
          this.$jsonPost(`/activity/product_sku/replenish/${this.id}/${this.form.replenish}`).then(data => {
            this.$Notice.success({
              title: '补货成功'
            })
          })
          this.modalView = false
          this.$store.commit('setQuality', {isLimitBrand: this.isLimitBrand, replenish: this.form.replenish, acId: this.id})
        }  
      })
    },
    onAgreeCancel() {
      this.modalView = false
    }
  }
}
</script>